<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>Open Event Machine API: test_appl_hello.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Open Event Machine API
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('test_appl_hello_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">test_appl_hello.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> *   Copyright (c) 2012, Nokia Siemens Networks</span></div>
<div class="line"><span class="comment"> *   All rights reserved.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> *   Redistribution and use in source and binary forms, with or without</span></div>
<div class="line"><span class="comment"> *   modification, are permitted provided that the following conditions are met:</span></div>
<div class="line"><span class="comment"> *       * Redistributions of source code must retain the above copyright</span></div>
<div class="line"><span class="comment"> *         notice, this list of conditions and the following disclaimer.</span></div>
<div class="line"><span class="comment"> *       * Redistributions in binary form must reproduce the above copyright</span></div>
<div class="line"><span class="comment"> *         notice, this list of conditions and the following disclaimer in the</span></div>
<div class="line"><span class="comment"> *         documentation and/or other materials provided with the distribution.</span></div>
<div class="line"><span class="comment"> *       * Neither the name of Nokia Siemens Networks nor the</span></div>
<div class="line"><span class="comment"> *         names of its contributors may be used to endorse or promote products</span></div>
<div class="line"><span class="comment"> *         derived from this software without specific prior written permission.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span></div>
<div class="line"><span class="comment"> *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span></div>
<div class="line"><span class="comment"> *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span></div>
<div class="line"><span class="comment"> *   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY</span></div>
<div class="line"><span class="comment"> *   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span></div>
<div class="line"><span class="comment"> *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span></div>
<div class="line"><span class="comment"> *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span></div>
<div class="line"><span class="comment"> *   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span></div>
<div class="line"><span class="comment"> *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span></div>
<div class="line"><span class="comment"> *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="event__machine_8h.html" title="Event Machine API v1.0.">event_machine.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;environment.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;example.h&quot;</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define SPIN_COUNT   50000000</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span></div>
<div class="line">{</div>
<div class="line">  <span class="comment">// Destination queue for the reply event</span></div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a>   dest;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Sequence number</span></div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seq;</div>
<div class="line"></div>
<div class="line">} hello_event_t;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span></div>
<div class="line">{</div>
<div class="line">  <span class="comment">// Init before start</span></div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a>      this_eo;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a>      other_eo;</div>
<div class="line">  <span class="keywordtype">int</span>          is_a;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Init in start</span></div>
<div class="line">  <span class="keywordtype">char</span>         name[16];</div>
<div class="line">  <span class="keyword">volatile</span> <span class="keywordtype">int</span> spins;</div>
<div class="line"></div>
<div class="line">} my_eo_context_t;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span></div>
<div class="line">{</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue;</div>
<div class="line"> </div>
<div class="line">} my_queue_context_t;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">union</span></div>
<div class="line">{</div>
<div class="line">  <span class="keyword">struct</span></div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Allocate EO contexts from shared memory region</span></div>
<div class="line">    my_eo_context_t eo_context_a;</div>
<div class="line">    my_eo_context_t eo_context_b;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Queue context</span></div>
<div class="line">    my_queue_context_t queue_context_a;</div>
<div class="line">    my_queue_context_t queue_context_b;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// EO A&#39;s queue</span></div>
<div class="line">    <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue_a; </div>
<div class="line">  };</div>
<div class="line">  </div>
<div class="line">  uint8_t u8[2*ENV_CACHE_LINE_SIZE];</div>
<div class="line">  </div>
<div class="line">} hello_shm_t;</div>
<div class="line"></div>
<div class="line">COMPILE_TIME_ASSERT((<span class="keyword">sizeof</span>(hello_shm_t) % ENV_CACHE_LINE_SIZE) == 0, HELLO_SHM_T__SIZE_ERROR);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> ENV_LOCAL hello_shm_t *hello_shm = NULL;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/* </span></div>
<div class="line"><span class="comment"> * Local function prototypes</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">hello_start(my_eo_context_t* eo_ctx, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo);</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">hello_stop(my_eo_context_t* eo_ctx, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo);</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">hello_receive_event(my_eo_context_t* eo_ctx, em_event_t event, <a class="code" href="event__machine__types_8h.html#a2f5b3fb43add8103da34b52cc1d0f2cc" title="Event type.">em_event_type_t</a> type, <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue, my_queue_context_t* q_ctx);</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">delay_spin(my_eo_context_t* eo_ctx);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span></div>
<div class="line">test_init(appl_conf_t *<span class="keyword">const</span> appl_conf)</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a>        eo_a, eo_b;</div>
<div class="line">  </div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(<a name="a0"></a><a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>() == 0) {</div>
<div class="line">    hello_shm = env_shared_reserve(<span class="stringliteral">&quot;HelloSharedMem&quot;</span>, <span class="keyword">sizeof</span>(hello_shm_t));</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span> {</div>
<div class="line">    hello_shm = env_shared_lookup(<span class="stringliteral">&quot;HelloSharedMem&quot;</span>);</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">if</span>(hello_shm == NULL) {</div>
<div class="line">    <a name="a1"></a><a class="code" href="event__machine_8h.html#a1d45cd3fa718f99bce956904b5e081de" title="Report an error.">em_error</a>(EM_ERROR_SET_FATAL(0xec0de), 0xdead, <span class="stringliteral">&quot;Hello init failed on EM-core: %u\n&quot;</span>, <a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>());</div>
<div class="line">  }</div>
<div class="line">    </div>
<div class="line"></div>
<div class="line">  <span class="comment">/*</span></div>
<div class="line"><span class="comment">   * Rest of the initializations only on one EM-core, return on all others.</span></div>
<div class="line"><span class="comment">   */</span>  </div>
<div class="line">  <span class="keywordflow">if</span>(<a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>() != 0)</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">return</span>;</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line">  </div>
<div class="line">  printf(<span class="stringliteral">&quot;\n**********************************************************************\n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;EM APPLICATION: &#39;%s&#39; initializing: \n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;  %s: %s() - EM-core:%i \n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;  Application running on %d EM-cores (procs:%d, threads:%d).&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;\n**********************************************************************\n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;\n&quot;</span></div>
<div class="line">         ,</div>
<div class="line">         appl_conf-&gt;name,</div>
<div class="line">         NO_PATH(__FILE__), __func__,</div>
<div class="line">         <a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>(),</div>
<div class="line">         <a name="a2"></a><a class="code" href="event__machine_8h.html#a84fa6ec801b82a586ff5e31693d3deb8" title="The number of cores running within the same EM instance (sharing the EM state).">em_core_count</a>(),</div>
<div class="line">         appl_conf-&gt;num_procs,</div>
<div class="line">         appl_conf-&gt;num_threads);</div>
<div class="line">  </div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  memset(&amp;hello_shm-&gt;eo_context_a, 0, <span class="keyword">sizeof</span>(my_eo_context_t));</div>
<div class="line">  memset(&amp;hello_shm-&gt;eo_context_b, 0, <span class="keyword">sizeof</span>(my_eo_context_t));</div>
<div class="line"></div>
<div class="line">  memset(&amp;hello_shm-&gt;queue_context_a, 0, <span class="keyword">sizeof</span>(my_queue_context_t));</div>
<div class="line">  memset(&amp;hello_shm-&gt;queue_context_b, 0, <span class="keyword">sizeof</span>(my_queue_context_t));</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  <span class="comment">//</span></div>
<div class="line">  <span class="comment">// Create both EOs</span></div>
<div class="line">  <span class="comment">//</span></div>
<div class="line">  eo_a = <a name="a3"></a><a class="code" href="event__machine_8h.html#a196c7caa1177575fd424e9a0d2854da6" title="Create Execution Object (EO).">em_eo_create</a>(<span class="stringliteral">&quot;EO A&quot;</span>,</div>
<div class="line">                      (<a name="a4"></a><a class="code" href="event__machine_8h.html#ac6c4b00c8090f4ef144d8b83c0474dbf" title="Execution object start, global.">em_start_func_t</a>)  hello_start, NULL,</div>
<div class="line">                      (<a name="a5"></a><a class="code" href="event__machine_8h.html#a0057112dd786c5f667bf42a424679c89" title="Execution object stop, global.">em_stop_func_t</a>)   hello_stop,  NULL, </div>
<div class="line">                      (<a name="a6"></a><a class="code" href="event__machine_8h.html#af132a04504b399fd5f59521f4f16306f" title="Receive event.">em_receive_func_t</a>)hello_receive_event, </div>
<div class="line">                      &amp;hello_shm-&gt;eo_context_a</div>
<div class="line">                     );</div>
<div class="line">                     </div>
<div class="line">  <span class="keywordflow">if</span>(eo_a == <a name="a7"></a><a class="code" href="event__machine__types_8h.html#af28fb8daf62b942ced417e158ed7e1c7" title="Invalid EO id.">EM_EO_UNDEF</a>)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;EO A creation failed! \n&quot;</span>);</div>
<div class="line">    <span class="keywordflow">return</span>;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  eo_b = <a class="code" href="event__machine_8h.html#a196c7caa1177575fd424e9a0d2854da6" title="Create Execution Object (EO).">em_eo_create</a>(<span class="stringliteral">&quot;EO B&quot;</span>,</div>
<div class="line">                      (<a class="code" href="event__machine_8h.html#ac6c4b00c8090f4ef144d8b83c0474dbf" title="Execution object start, global.">em_start_func_t</a>)  hello_start, NULL,</div>
<div class="line">                      (<a class="code" href="event__machine_8h.html#a0057112dd786c5f667bf42a424679c89" title="Execution object stop, global.">em_stop_func_t</a>)   hello_stop,  NULL, </div>
<div class="line">                      (<a class="code" href="event__machine_8h.html#af132a04504b399fd5f59521f4f16306f" title="Receive event.">em_receive_func_t</a>)hello_receive_event, </div>
<div class="line">                      &amp;hello_shm-&gt;eo_context_b</div>
<div class="line">                     );</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(eo_b == <a class="code" href="event__machine__types_8h.html#af28fb8daf62b942ced417e158ed7e1c7" title="Invalid EO id.">EM_EO_UNDEF</a>)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;EO B creation failed! \n&quot;</span>);</div>
<div class="line">    <span class="keywordflow">return</span>;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  <span class="comment">// Init EO contexts</span></div>
<div class="line">  hello_shm-&gt;eo_context_a.this_eo  = eo_a;</div>
<div class="line">  hello_shm-&gt;eo_context_a.other_eo = eo_b;</div>
<div class="line">  hello_shm-&gt;eo_context_a.is_a     = 1;</div>
<div class="line"></div>
<div class="line">  hello_shm-&gt;eo_context_b.this_eo  = eo_b;</div>
<div class="line">  hello_shm-&gt;eo_context_b.other_eo = eo_a;</div>
<div class="line">  hello_shm-&gt;eo_context_b.is_a     = 0;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Start EO A</span></div>
<div class="line">  <a name="a8"></a><a class="code" href="event__machine_8h.html#a97445f266a00782bb23fc2c464533d6d" title="Start Execution Object (EO).">em_eo_start</a>(eo_a, NULL, 0, NULL);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Start EO B</span></div>
<div class="line">  <a class="code" href="event__machine_8h.html#a97445f266a00782bb23fc2c464533d6d" title="Start Execution Object (EO).">em_eo_start</a>(eo_b, NULL, 0, NULL);</div>
<div class="line"> </div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">hello_start(my_eo_context_t* eo_ctx, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo)</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue;</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>* queue_name;</div>
<div class="line">  my_queue_context_t* q_ctx;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a> status;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Copy EO name</span></div>
<div class="line">  <a name="a9"></a><a class="code" href="event__machine_8h.html#ae4fbadae4cc0158b24fdcdb6cf5e04fe" title="Returns the name given to the EO when it was created.">em_eo_get_name</a>(eo, eo_ctx-&gt;name, <span class="keyword">sizeof</span>(eo_ctx-&gt;name));</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">if</span>(eo_ctx-&gt;is_a)</div>
<div class="line">  {</div>
<div class="line">    queue_name = <span class="stringliteral">&quot;queue A&quot;</span>;</div>
<div class="line">    q_ctx      = &amp;hello_shm-&gt;queue_context_a;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span></div>
<div class="line">  {</div>
<div class="line">    queue_name = <span class="stringliteral">&quot;queue B&quot;</span>;</div>
<div class="line">    q_ctx      = &amp;hello_shm-&gt;queue_context_b;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  queue = <a name="a10"></a><a class="code" href="event__machine_8h.html#a15c0cb536f8c7c01692ccea07908944a" title="Create a new queue with a dynamic queue id.">em_queue_create</a>(queue_name, EM_QUEUE_TYPE_ATOMIC, EM_QUEUE_PRIO_NORMAL, EM_QUEUE_GROUP_DEFAULT);</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(queue == <a name="a11"></a><a class="code" href="event__machine__types_8h.html#ae8ba676fb5528d220363edad0aeef1ff" title="Invalid queue.">EM_QUEUE_UNDEF</a>)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;%s creation failed! \n&quot;</span>, queue_name);</div>
<div class="line">    <span class="keywordflow">return</span> <a name="a12"></a><a class="code" href="event__machine__types_8h.html#a1f9dbd41491db385bd4a3813e2f030a5" title="Operation not successful.">EM_ERROR</a>;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  q_ctx-&gt;queue = queue;</div>
<div class="line"></div>
<div class="line">  status = <a name="a13"></a><a class="code" href="event__machine_8h.html#a83e001b62c2a87bf862fbf695c5e84fa" title="Set queue specific (application) context.">em_queue_set_context</a>(queue, q_ctx);</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(status != <a name="a14"></a><a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Set queue context failed! status: %i,  eo: %&quot;</span><a name="a15"></a><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a name="a16"></a><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, status, eo, queue);</div>
<div class="line">    <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a1f9dbd41491db385bd4a3813e2f030a5" title="Operation not successful.">EM_ERROR</a>;</div>
<div class="line">  }  </div>
<div class="line"></div>
<div class="line">  </div>
<div class="line">  status = <a name="a17"></a><a class="code" href="event__machine_8h.html#a681c9d79f7ca5c0590030f74357472c0" title="Add a queue to an EO.">em_eo_add_queue</a>(eo, queue);</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(status != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Add queue failed! status: %i,  eo: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, status, eo, queue);</div>
<div class="line">    <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a1f9dbd41491db385bd4a3813e2f030a5" title="Operation not successful.">EM_ERROR</a>;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  </div>
<div class="line">  status = <a name="a18"></a><a class="code" href="event__machine_8h.html#adcbab74b22ffcb629bdf797704ac2706" title="Enable event scheduling for the queue.">em_queue_enable</a>(queue);</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(status != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Queue enable failed! status: %i,  eo: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, status, eo, queue);</div>
<div class="line">    <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a1f9dbd41491db385bd4a3813e2f030a5" title="Operation not successful.">EM_ERROR</a>;</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  printf(<span class="stringliteral">&quot;Hello world started %s. I&#39;m EO %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;. My queue is %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot;.\n&quot;</span>, eo_ctx-&gt;name, eo, queue);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">if</span>(eo_ctx-&gt;is_a)</div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Save queue ID for EO B.</span></div>
<div class="line">    hello_shm-&gt;queue_a = queue;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span></div>
<div class="line">  {</div>
<div class="line">    em_event_t     event;</div>
<div class="line">    hello_event_t* hello;</div>
<div class="line"></div>
<div class="line">    <span class="comment">//</span></div>
<div class="line">    <span class="comment">// Send the first event to EO A.</span></div>
<div class="line">    <span class="comment">// Store queue ID as the destination queue for EO A.</span></div>
<div class="line">    <span class="comment">//</span></div>
<div class="line">    <span class="keyword">event</span> = <a name="a19"></a><a class="code" href="event__machine_8h.html#a22fcb41f303628eebe4f0b45b6c64ab0" title="Allocate an event.">em_alloc</a>(<span class="keyword">sizeof</span>(hello_event_t), EM_EVENT_TYPE_SW, EM_POOL_DEFAULT);</div>
<div class="line">  </div>
<div class="line">    <span class="keywordflow">if</span>(event == EM_EVENT_UNDEF)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;Event allocation failed! \n&quot;</span>);</div>
<div class="line">      <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a1f9dbd41491db385bd4a3813e2f030a5" title="Operation not successful.">EM_ERROR</a>;</div>
<div class="line">    }</div>
<div class="line">  </div>
<div class="line">    hello = em_event_pointer(event);</div>
<div class="line">    hello-&gt;dest = queue;</div>
<div class="line">    hello-&gt;seq  = 0;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">    status = <a name="a20"></a><a class="code" href="event__machine_8h.html#aca4584a01b71429dfbb045342454b464" title="Send an event to a queue.">em_send</a>(event, hello_shm-&gt;queue_a);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span>(status != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;em_send() failed! status: %i,  eo: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, status, eo, hello_shm-&gt;queue_a);</div>
<div class="line">      <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a1f9dbd41491db385bd4a3813e2f030a5" title="Operation not successful.">EM_ERROR</a>;</div>
<div class="line">    }</div>
<div class="line">    </div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">hello_stop(my_eo_context_t* eo_ctx, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo)</div>
<div class="line">{</div>
<div class="line">  printf(<span class="stringliteral">&quot;Hello world stop (%s, eo id %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;)\n&quot;</span>, eo_ctx-&gt;name, eo);</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">hello_receive_event(my_eo_context_t* eo_ctx, em_event_t event, <a class="code" href="event__machine__types_8h.html#a2f5b3fb43add8103da34b52cc1d0f2cc" title="Event type.">em_event_type_t</a> type, <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue, my_queue_context_t* q_ctx)</div>
<div class="line">{</div>
<div class="line">  hello_event_t* hello;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a>     dest;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a>    status;</div>
<div class="line"></div>
<div class="line">  </div>
<div class="line">  (void)type;</div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  hello = em_event_pointer(event);</div>
<div class="line"></div>
<div class="line">  dest        = hello-&gt;dest;</div>
<div class="line">  hello-&gt;dest = queue;</div>
<div class="line"></div>
<div class="line">  printf(<span class="stringliteral">&quot;Hello world from %s! My queue is %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot;. I&#39;m on core %02i. Event seq is %u.\n&quot;</span>, eo_ctx-&gt;name, q_ctx-&gt;queue, <a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>(), hello-&gt;seq++);</div>
<div class="line"></div>
<div class="line">  delay_spin(eo_ctx);</div>
<div class="line"></div>
<div class="line">  status = <a class="code" href="event__machine_8h.html#aca4584a01b71429dfbb045342454b464" title="Send an event to a queue.">em_send</a>(event, dest);</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(status != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>) {</div>
<div class="line">    printf(<span class="stringliteral">&quot;em_send() failed! status: %i,  eo: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, status, eo_ctx-&gt;this_eo, hello_shm-&gt;queue_a);</div>
<div class="line">  }  </div>
<div class="line"></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">delay_spin(my_eo_context_t* eo_ctx)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordtype">int</span> i;</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">for</span>(i = 0; i &lt; SPIN_COUNT; i++)</div>
<div class="line">  {</div>
<div class="line">    eo_ctx-&gt;spins++;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Wed Aug 7 2013 15:17:39 for Open Event Machine API by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3.1 </li>
  </ul>
</div>
</body>
</html>
